package com.zhehekeji.opsys.api.service.manager;

import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mongodb.client.MongoCollection;
import com.zhehekeji.opsys.api.cache.OperationCache;
import com.zhehekeji.opsys.api.cache.ReportCache;
import com.zhehekeji.opsys.api.common.dao.EntityDao;
import com.zhehekeji.opsys.api.common.util.DateFormatUtil;
import com.zhehekeji.opsys.api.common.util.ResultCode;
import com.zhehekeji.opsys.api.dao.MongoDaoImpl;
import com.zhehekeji.opsys.api.enm.MongoCollectionName;
import com.zhehekeji.opsys.api.enm.SysconfigKey;
import com.zhehekeji.opsys.api.entity.TStatisticsObject;
import com.zhehekeji.opsys.api.resp.DateReportButtonLogListResp;
import com.zhehekeji.opsys.api.resp.DateReportListResp;
import com.zhehekeji.opsys.api.resp.DateReportOrderLogListResp;
import com.zhehekeji.opsys.api.resp.DateReportResp;
import com.zhehekeji.opsys.api.resp.DateReportSearchHisListResp;
import com.zhehekeji.opsys.api.resp.DateReportVodTimeListResp;
import com.zhehekeji.opsys.api.util.UUIDUtils;
import com.zhehekeji.opsys.api.vo.ReportParam;

/**
 * @ClassName MongoDataReportService
 * @Description TODO
 * @date 2015-5-29   下午3:01:56
 */
public class MongoDataReportService implements IDataReportService {

    private static Logger logger = LoggerFactory.getLogger(MongoDataReportService.class);

    private MongoDaoImpl mongoDao;

    @Autowired
    protected EntityDao entityDao;
    @Autowired
    protected OperationCache operationCache;
    @Autowired
    protected ReportCache reportCache;

    public void setMongoDao(MongoDaoImpl mongoDao) {
        this.mongoDao = mongoDao;
    }

    /**
     * 获取点播时长上限配置
     *
     * @return
     */
    private long getVodTimeLimit() {
        //默认4小时：4*3600=14400
        long tmpVodTimeLimit = 14400;
        try {
            String tmp = operationCache.getSysconfig(SysconfigKey.VOD_TIME_LIMIT.getKey());
            if (!StringUtils.isBlank(tmp)) {
                tmpVodTimeLimit = NumberUtils.toLong(tmp, tmpVodTimeLimit);
            }
        } catch (SQLException e) {
            logger.error("获取点播时长上限配置失败", e);
        }
        return tmpVodTimeLimit;
    }

    /**
     * 00@00@00@00
     * 从左至右依次为
     * 1、CP编号，如优朋、行云等；
     * 2、专区编号，如大片、首映、卡通等；
     * 3、收费、免费；
     * 4、节目所属分类，如电影、电视剧、少儿、综艺、体育等。
     * <p>
     * 以上编号00均预留为空值，允许部分节目个别参数为空。
     * 这是武汉李丹丹给的参数说明
     *
     * @param cpID
     * @return
     */
    private ReportParam getReportParam(String cpID) {
        ReportParam tmpReportParam = new ReportParam();
        if (StringUtils.isBlank(cpID)) {
            tmpReportParam.setCpID("0");
            return tmpReportParam;
        }
        if (cpID.indexOf("@") == -1) {
            tmpReportParam.setCpID(cpID);
            return tmpReportParam;
        }
        String[] tmpArray = cpID.split("@");

        for (int i = 0; i < tmpArray.length; i++) {
            if (i == 0) {
                String tmpActualCpID = tmpArray[0];
                if (StringUtils.isBlank(tmpActualCpID)) {
                    continue;
                }
                if (tmpActualCpID.equals("00")) {
                    tmpReportParam.setCpID("0");
                } else {
                    tmpReportParam.setCpID(tmpActualCpID);
                }
            }
            if (i == 1) {
                String tmpObjectCode = tmpArray[1];
                if (StringUtils.isBlank(tmpObjectCode)) {
                    continue;
                }
                if (tmpObjectCode.equals("00")) {
                    tmpReportParam.setObjectCode(null);
                } else {
                    tmpReportParam.setObjectCode(tmpObjectCode);
                }
            }
            if (i == 2) {
                String tmpPayFlag = tmpArray[2];
                if (StringUtils.isBlank(tmpPayFlag)) {
                    continue;
                }
                if (tmpPayFlag.equals("00")) {
                    tmpReportParam.setPayFlag(null);
                } else {
                    tmpReportParam.setPayFlag(tmpPayFlag);
                }
            }
            if (i == 3) {
                String tmpClassify = tmpArray[3];
                if (StringUtils.isBlank(tmpClassify)) {
                    continue;
                }
                if (tmpClassify.equals("00")) {
                    tmpReportParam.setClassify(null);
                } else {
                    tmpReportParam.setClassify(tmpClassify);
                }
            }
        }
        return tmpReportParam;
    }

    private String getActualAreaID(String cpID, String areaID) {
        if (StringUtils.isBlank(cpID)) {
            return areaID;
        }
        if (cpID.indexOf("@") == -1) {
            return areaID;
        }
        String tmpActualAreaID = areaID + "$" + cpID;
        if (tmpActualAreaID.length() > 64) {
            tmpActualAreaID = tmpActualAreaID.substring(0, 64);
        }
        return tmpActualAreaID;
    }

    @Override
    public DateReportResp addVisitLog(String userID, String stb, String cpID, int type, String productName,
			String productCode, int resolution, String areaID, String provinceIdentity, String provinceName,
			String parentPageIdentity, int epgPlatformType) {

        DateReportResp resp = new DateReportResp();
        
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            
            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TVisitLog.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("cpCode", tmpCpID)
                    .append("productCode", productCode)
                    .append("productName", productName)
                    .append("type", type)
                    .append("visitTime", DateFormatUtil.format(new Date()))
                    .append("resolution", resolution)
                    .append("areaId", getActualAreaID(cpID, areaID))
                    .append("epgPlatformType", epgPlatformType)
                    .append("stbType", stb);
            tmpCollection.insertOne(tmpDocument);
            
            logger.info("添加用户访问日志成功");
        } catch (Exception e) {
            logger.error("添加用户访问日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加用户访问日志失败，系统异常");
        }
        return resp;
    
	}

    @Override
    public DateReportResp addVodLog(String userID, String contentCode,
                                    String contentName, String cpID, String productCode, int type,
                                    String seriesCode, String seriesName, String productName,
                                    int category, int resolution, String areaID, int epgPlatformType, String stb) {
        DateReportResp resp = new DateReportResp();
        if (StringUtils.isBlank(contentCode)) {
            logger.error("添加详情页访问次数日志失败，内容编码非法");
            resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
            resp.setResultDesc("添加详情页访问次数日志失败，内容编码非法");
            return resp;
        }
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            String tmpProductName = productName;
            String tmpProductCode = productCode;

            String tmpObjectCode = tmpReportParam.getObjectCode();
            if (!StringUtils.isBlank(tmpObjectCode)) {
                tmpProductCode = tmpObjectCode;
                //TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
                TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
                if (tmpTStatisticsObject != null) {
                    tmpProductName = tmpTStatisticsObject.getName();
                }
            }

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TVodLog.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("cid", contentCode)
                    .append("cname", contentName)
                    .append("cpCode", tmpCpID)
                    .append("productCode", tmpProductCode)
                    .append("productName", tmpProductName)
                    .append("seriesCode", seriesCode)
                    .append("seriesName", seriesName)
                    .append("type", type)
                    .append("isCarry", 0)
                    .append("visitTime", DateFormatUtil.format(new Date()))
                    .append("resolution", resolution)
                    .append("areaId", getActualAreaID(cpID, areaID))
                    .append("category", category)
                    .append("epgPlatformType", epgPlatformType)
                    .append("stbType", stb);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加详情页访问次数日志成功");
        } catch (Exception e) {
            logger.error("添加详情页访问次数日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加详情页访问次数日志失败，系统异常");
        }
        return resp;
    }

    @Override
    public DateReportResp addVodTimeLog(String userID, String stb, int platformType, String cpID, int type,
                                        String pageIdentity, String pageName,
                                        String provinceIdentity, String provinceName, String parentPageIdentity,
                                        String contentCode, String contentName, String categoryCode, String categoryName,
                                        Long playTime, String seriesCode, String seriesName, String operatorIdentity, String operatorName,String utype,String ptype, String resolution) {
        DateReportResp resp = new DateReportResp();
        Date currentDate = new Date();
        if (StringUtils.isBlank(contentCode)) {
            logger.error("添加影片访问时长日志失败，内容编码非法");
            resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
            resp.setResultDesc("添加影片访问时长日志失败，内容编码非法");
            return resp;
        }
        //if (StringUtils.isBlank(startTime)){
        //	logger.error("添加影片访问时长日志失败，起播时间非法");
        //	resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
        //	resp.setResultDesc("添加影片访问时长日志失败，起播时间非法");
        //	return resp;
        //}
        String timeTemplate = "yyyyMMddHHmmss";
        Date startDate = null;
        //try{
        //	startDate = DateUtils.parseDate(startTime, new String[]{timeTemplate});
        //}catch (ParseException e){
        //	logger.error("添加影片访问时长日志失败，起播时间格式必须为" + timeTemplate);
        //	resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
        //	resp.setResultDesc("添加影片访问时长日志失败，起播时间格式必须为" + timeTemplate);
        //	return resp;
        //}
        Date endDate = null;
        //if (StringUtils.isBlank(endTime)){
        //	endDate = currentDate;
        //}else{
        //	try{
        //		endDate = DateUtils.parseDate(endTime, new String[]{timeTemplate});
        //    }catch (ParseException e){
        //    	logger.error("添加影片访问时长日志失败，止播时间格式必须为" + timeTemplate);
        //    	resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
        //		resp.setResultDesc("添加影片访问时长日志失败，止播时间格式必须为" + timeTemplate);
        //		return resp;
        //    }
        //}
        //时长（秒）
        //Long times = (endDate.getTime() - startDate.getTime()) / 1000;
        //if (times < 0) times = 0L;

        //2017-06-28添加
        long tmpVodTimeLimit = getVodTimeLimit();
        //if (times > tmpVodTimeLimit){
        //	logger.error(String.format("添加影片访问时长日志失败，观看影片时长超过[%s]秒，实际观看时长[%s]秒", tmpVodTimeLimit, times));
        //	resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
        //	resp.setResultDesc(String.format("添加影片访问时长日志失败，观看影片时长超过[%s]秒，实际观看时长[%s]秒", tmpVodTimeLimit, times));
        //	return resp;
        //}

        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            //String tmpProductName = productName;
            //String tmpProductCode = productCode;

            String tmpObjectCode = tmpReportParam.getObjectCode();
            //if (!StringUtils.isBlank(tmpObjectCode)){
            //	tmpProductCode = tmpObjectCode;
            //	//TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
            //	TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
            //	if (tmpTStatisticsObject != null){
            //		tmpProductName = tmpTStatisticsObject.getName();
            //	}
            //}

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TVodTimeLog.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("cid", contentCode)
                    .append("cname", contentName)
                    .append("cpCode", tmpCpID)
                    .append("endTime", DateFormatUtil.format(endDate))
                    //.append("productCode", tmpProductCode)
                    //.append("productName", tmpProductName)
                    .append("seriesCode", seriesCode)
                    .append("seriesName", seriesName)
                    .append("startTime", DateFormatUtil.format(startDate))
                    //.append("times", times + "")
                    .append("type", type)
                    .append("isCarry", 0)
                    .append("visitTime", DateFormatUtil.format(currentDate))
                    //.append("resolution", resolution)
                    //.append("areaId", getActualAreaID(cpID, areaID))
                    //.append("category",category)
                    //.append("epgPlatformType",epgPlatformType)
                    .append("stbType", stb);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加影片访问时长日志成功");
        } catch (Exception e) {
            logger.error("添加影片访问时长日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加详情页访问次数日志失败，系统异常");
        }
        return resp;
    }

    @Override
    public DateReportResp addOrderLog(String userID, String stb, int action, int platformType, String cpID, int type,
                                      String pageIdentity, String pageName,
                                      String provinceIdentity, String provinceName, String parentPageIdentity,
                                      String contentCode, String contentName, String categoryCode, String categoryName,
                                      double origPrice, double price, String operatorIdentity, String operatorName,String ptype, String resolution, String comFrom) {
        DateReportResp resp = new DateReportResp();
        //if (StringUtils.isBlank(productCode)){
        //	logger.error("添加订购日志失败，产品编码非法");
        //	resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
        //	resp.setResultDesc("添加订购日志失败，产品编码非法");
        //	return resp;
        //}
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            //String tmpProductName = productName;
            //String tmpProductCode = productCode;

            //String tmpObjectCode = tmpReportParam.getObjectCode();
            //if (!StringUtils.isBlank(tmpObjectCode)){
            //	tmpProductCode = tmpObjectCode;
            //	//TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
            //	TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
            //	if (tmpTStatisticsObject != null){
            //		tmpProductName = tmpTStatisticsObject.getName();
            //	}
            //}

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TOrderLog.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("action", action)
                    .append("cpCode", tmpCpID)
                    .append("createTime", DateFormatUtil.format(new Date()))
                    //.append("productCode", tmpProductCode)
                    //.append("productName", tmpProductName)
                    .append("origPrice", origPrice)
                    .append("price", price)
                    //.append("comeFrom", comeFrom)
                    .append("isCarry", 0)
                    //.append("resolution", resolution)
                    //.append("areaId", getActualAreaID(cpID, areaID))
                    .append("type", type)
                    //.append("epgPlatformType", epgPlatformType)
                    .append("stbType", stb);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加订购日志成功");
        } catch (Exception e) {
            logger.error("添加订购日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加订购日志成功，系统异常");
        }
        return resp;
    }

    @Override
    public DateReportResp addComplainLog(String userID, String stb, String ip,
                                         String productCode, String productName, String cpID, int type,
                                         int resolution, String areaID, int epgPlatformType) {
        DateReportResp resp = new DateReportResp();
        if (StringUtils.isBlank(productCode)) {
            logger.error("添加投诉日志失败，产品编码非法");
            resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
            resp.setResultDesc("添加投诉日志失败，产品编码非法");
            return resp;
        }
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            String tmpProductName = productName;
            String tmpProductCode = productCode;

            String tmpObjectCode = tmpReportParam.getObjectCode();
            if (!StringUtils.isBlank(tmpObjectCode)) {
                tmpProductCode = tmpObjectCode;
                //TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
                TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
                if (tmpTStatisticsObject != null) {
                    tmpProductName = tmpTStatisticsObject.getName();
                }
            }

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TComplain.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("complainIp", ip)
                    .append("complainTime", DateFormatUtil.format(new Date()))
                    .append("cpCode", tmpCpID)
                    .append("objectCode", tmpProductCode)
                    .append("objectName", tmpProductName)
                    .append("isCarry", 0)
                    .append("stbType", stb)
                    .append("resolution", resolution)
                    .append("areaId", getActualAreaID(cpID, areaID))
                    .append("type", type)
                    .append("epgPlatformType", epgPlatformType);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加投诉日志成功");
        } catch (Exception e) {
            logger.error("添加投诉日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加投诉日志失败，系统异常");
        }
        return resp;
    }

    @Override
    public DateReportResp addPPVOrderLog(String userID, String contentCode,
                                         String contentName, double origPrice, double price, int resolution,
                                         int comeFrom, String cpID, String areaID, String productCode,
                                         String productName, int epgPlatformType, String stb) {
        DateReportResp resp = new DateReportResp();
        if (StringUtils.isBlank(contentCode)) {
            logger.error("添加PPV订购日志失败，内容编码非法");
            resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
            resp.setResultDesc("添加PPV订购日志失败，内容编码非法");
            return resp;
        }
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            String tmpProductName = productName;
            String tmpProductCode = productCode;

            String tmpObjectCode = tmpReportParam.getObjectCode();
            if (!StringUtils.isBlank(tmpObjectCode)) {
                tmpProductCode = tmpObjectCode;
                //TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
                TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
                if (tmpTStatisticsObject != null) {
                    tmpProductName = tmpTStatisticsObject.getName();
                }
            }

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.TPpvOrderLog.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("cid", contentCode)
                    .append("cname", contentName)
                    .append("cpCode", tmpCpID)
                    .append("createTime", DateFormatUtil.format(new Date()))
                    .append("origPrice", origPrice)
                    .append("price", price)
                    .append("comeFrom", comeFrom)
                    .append("isCarry", 0)
                    .append("areaId", getActualAreaID(cpID, areaID))
                    .append("resolution", resolution)
                    .append("productCode", tmpProductCode)
                    .append("productName", tmpProductName)
                    .append("epgPlatformType", epgPlatformType)
                    .append("stbType", stb);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加PPV订购日志成功");
        } catch (Exception e) {
            logger.error("添加PPV订购日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加PPV订购日志失败，系统异常");
        }
        return resp;
    }

    @Override
    public DateReportResp addHomepageLog(String userID, String homepageCode,
                                         String homepageName, String location, int resolution, String cpID,
                                         String areaID, int epgPlatformType, String stb) {
        DateReportResp resp = new DateReportResp();
        if (StringUtils.isBlank(homepageCode)) {
            logger.error("添加首页访问日志失败，产品编码非法");
            resp.setResultCode(ResultCode.PARAMETER_IS_NOT_LEGAL);
            resp.setResultDesc("添加首页访问日志失败，产品编码非法");
            return resp;
        }
        try {
            ReportParam tmpReportParam = getReportParam(cpID);
            long tmpCpID = NumberUtils.toLong(tmpReportParam.getCpID());
            String tmpProductName = homepageName;
            String tmpProductCode = homepageCode;

            String tmpObjectCode = tmpReportParam.getObjectCode();
            if (!StringUtils.isBlank(tmpObjectCode)) {
                tmpProductCode = tmpObjectCode;
                //TStatisticsObject tmpTStatisticsObject = entityDao.get(TStatisticsObject.class, "o.code=?1 and o.cpCode=?2", new Object[]{tmpObjectCode, tmpCpID});
                TStatisticsObject tmpTStatisticsObject = reportCache.getStatisticsObject(tmpObjectCode, tmpCpID);
                if (tmpTStatisticsObject != null) {
                    tmpProductName = tmpTStatisticsObject.getName();
                }
            }

            MongoCollection<Document> tmpCollection = mongoDao.getCollection(MongoCollectionName.THomepage.getName());
            Document tmpDocument = new Document();
            tmpDocument.append("code", UUIDUtils.randomUUID())
                    .append("account", userID)
                    .append("cpCode", tmpCpID)
                    .append("homepageCode", tmpProductCode)
                    .append("homepageName", tmpProductName)
                    .append("stbType", stb)
                    .append("isCarry", 0)
                    .append("visitTime", DateFormatUtil.format(new Date()))
                    .append("resolution", resolution)
                    .append("areaId", getActualAreaID(cpID, areaID))
                    .append("location", location)
                    .append("epgPlatformType", epgPlatformType);
            tmpCollection.insertOne(tmpDocument);
            logger.info("添加首页访问日志成功");
        } catch (Exception e) {
            logger.error("添加首页访问日志失败，系统异常，" + e.getMessage(), e);
            resp.setResultCode(ResultCode.APPLICATION_EXCEPTION);
            resp.setResultDesc("添加首页访问日志失败，系统异常");
        }
        return resp;
    }

	@Override
	public DateReportResp addPageLog(String userID, String stb, int platformType, String cpID, int type,
			String pageIdentity, String pageName, String buttonIdentity, String buttonName, String provinceIdentity,
			String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode,
			String categoryName) {
		logger.info("添加页面访问日志成功--");
		DateReportResp resp = new DateReportResp();
		return resp;
	}

	@Override
	public DateReportResp addButtonLog(String userID, String stb, int platformType, String cpID, int type,
			String pageIdentity, String pageName, String buttonIdentity, String buttonName, String provinceIdentity,
			String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode,
			String categoryName) {
		logger.info("添加按钮访问日志成功--");
		DateReportResp resp = new DateReportResp();
		return resp;
	}

	@Override
	public DateReportListResp getPageLogList(String stb, String userID, int firstIndex, int maxResult) {
		DateReportListResp resp = new DateReportListResp();
		return resp;
	}

	@Override
	public DateReportButtonLogListResp getButtonLogList(String stb, String userID, int firstIndex, int maxResult) {
		DateReportButtonLogListResp resp = new DateReportButtonLogListResp();
		return resp;
	}

	@Override
	public DateReportVodTimeListResp getVodTimeLogList(String stb, String userID, int firstIndex, int maxResult) {
		DateReportVodTimeListResp resp = new DateReportVodTimeListResp();
		return resp;
	}

	@Override
	public DateReportOrderLogListResp getOrderLogList(String stb, String userID, int firstIndex, int maxResult) {
		DateReportOrderLogListResp resp = new DateReportOrderLogListResp();
		return resp;
	}

	@Override
	public DateReportResp addVisitLog(String userID, String stb, int platformType, String cpID, int type,
			String pageIdentity, String pageName, String buttonIdentity, String buttonName, String provinceIdentity,
			String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode,
			String categoryName,String operatorIdentity, String operatorName, String parentPageName, String utype, 
            String otype, String originRecommend, String ptype, String resolution) {
		logger.info("添加访问日志成功--");
		DateReportResp resp = new DateReportResp();
		return resp;
	}

	@Override
	public DateReportListResp getPageLogListhn(String stb, String userID, int firstIndex, int maxResult) {
		DateReportListResp resp = new DateReportListResp();
		return resp;
	}

	@Override
	public DateReportButtonLogListResp getButtonLogListhn(String stb, String userID, int firstIndex, int maxResult) {
		DateReportButtonLogListResp resp = new DateReportButtonLogListResp();
		return resp;
	}

	@Override
	public DateReportResp addSearchHisLog(String userID, String key, String code, String name, String pageNo, String poster, String operatorIdentity, String operatorName, String resolution) {
		logger.info("addSearchHisLog--");
		return null;
	}

	@Override
	public DateReportSearchHisListResp getSearchHisList(String userID, int maxResult) {
		logger.info("getSearchHisList--");
		return null;
	}
}
